import TipPanel from "./TipPanel";
import StartPanel from "./StartPanel";
import GameManager from "../Manager/GameManager";


const {ccclass, property} = cc._decorator;

@ccclass
export default class WinLosePanel extends cc.Component {
    public static Instance:WinLosePanel;

    

    @property(cc.Label)
    Label_win:cc.Label = null;
    @property(cc.Label)
    Label_lose:cc.Label = null;

    @property(cc.Label)
    Label_score:cc.Label = null;
    
    @property(cc.Button)
    Button_close:cc.Button = null;
    @property(cc.Button)
    Button_main:cc.Button = null;
    @property(cc.Button)
    Button_replay:cc.Button = null;
    @property(cc.Button)
    Button_share:cc.Button = null;

    
    state:number;

    onLoad () {
        WinLosePanel.Instance = this;
    }

    start () {
        this.Button_close.node.on('click', this.click_close, this);
        this.Button_main.node.on('click', this.click_main, this);
        this.Button_replay.node.on('click', this.click_replay, this);
        this.Button_share.node.on('click', this.click_share, this);
    }

    ShowOn(_state:number)
    {
        this.node.active = true;

        this.state = _state;
        this.Label_win.node.active = this.state == 1;
        this.Label_lose.node.active = this.state == 2;

        this.RefreshScore(GameManager.Instance.score);
    }

    ShowOff()
    {
        this.node.active = false;
    }

    RefreshScore(_score:number)
    {
        this.Label_score.string = _score.toString();
    }

    click_close(button)
    {
        this.ShowOff();
        GameManager.Instance.GameOver();
        StartPanel.Instance.ShowOn();
    }
    click_main(button)
    {
        this.ShowOff();
        GameManager.Instance.GameOver();
        StartPanel.Instance.ShowOn();
    }
    click_replay(button)
    {
        this.ShowOff();
        GameManager.Instance.GameStart();
    }
    click_share(button)
    {
        TipPanel.Instance.Show("分享");
    }

}
